package com.kang.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kang.bean.UserRole;
import com.kang.mapper.UserRoleMapper;
import com.kang.service.UserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @program: service
 * @description:
 * @author: K.faWu
 * @create: 2022-03-04 14:32
 **/

@Service
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole> implements UserRoleService {
    @Autowired
    private UserRoleMapper userRoleMapper;

    @Override
    public void addOrUpdate(UserRole userRole) {
        QueryWrapper<UserRole> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id", userRole.getUserId());
        UserRole userRole1 = userRoleMapper.selectOne(wrapper);
        if (userRole1 != null){
            userRole.setId(userRole1.getId());
            userRoleMapper.updateById(userRole);
        }else{
            userRoleMapper.insert(userRole);
        }
    }
}
